﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserMenuEdit.aspx.cs" Inherits="GU.WebERPApp.Sys.UserMenuEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        body{width:500px;}
    </style>
    <script src="/Scripts/mini.boot.js" type="text/javascript"></script>
    <script src="/Scripts/Plugin/msgTip.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div style="float:left;">
            <table id="tb_userinfo" cellspacing="3" cellpadding="2" border="0">
                <tr>
                    <td>用户名：</td>
                    <td>
                        <input id="UserId" name="UserId" value="0" class="mini-hidden" />
                        <input id="UserName" name="UserName" style="width:180px;" class="mini-textbox" required="true" />
                    </td>
                </tr>
                <tr>
                    <td>密码：</td>
                    <td>
                        <input id="Password" name="Password" style="width:180px;" class="mini-password" />
                    </td>
                </tr>
                <tr>
                    <td>是否管理员：</td>
                    <td>
                        <input id="IsAdmin" name="IsAdmin" class="mini-checkbox"/>
                    </td>
                </tr>
                <tr>
                    <td>备注：</td>
                    <td>
                        <input id="Remark" name="Remark" style="width:180px;" class="mini-textbox" />
                    </td>
                </tr>
                <tr>
                    <td>权限：</td>
                    <td style="text-align:right;"><a class="mini-button" Plain="true" iconCls="icon-folderopen" onclick="openWin()">设置页面权限</a></td>
                </tr>
            </table>
        </div>

        <div style="float:left;margin-left:10px;border:1px solid #c0c0c0;">
            <ul id="tree1" class="mini-tree" style="width:200px;height:150px;" 
                showTreeIcon="true" textField="text"  idField="id" parentField="pid" resultAsTree="false"  
                expandOnLoad="true" expandOnDblClick="false" >
            </ul>
        </div>
        <div style="clear:both;"></div>
        <div style="text-align:center;margin-top:15px;">
            <a id="A3" class="mini-button" iconcls="icon-ok" plain="true" onclick="saveData()">  确定  </a>
            <span class="separator"></span>
            <a id="A4" class="mini-button" iconcls="icon-no" plain="true" onclick="closePage()">  取消  </a>
        </div>

        <div id="winTreeMenu" class="mini-window" title="Window" style="width:300px;height:300px;" 
            showFooter="true" showModal="true" allowDrag="true">
            <div property="footer" style="text-align:right;padding:5px;padding-right:15px;">
                <a id="A1" class="mini-button" iconcls="icon-ok" plain="true" onclick="onSelectMenu()">  确定  </a>
                <a id="A2" class="mini-button" iconcls="icon-no" plain="true" onclick="hideWindow()">  取消  </a>
            </div>
            <div class="mini-fit">
                <ul id="tree2" class="mini-tree" url="/methods/?method=itm.sys.menu.get" style="width:260px;padding:5px;" 
                    showTreeIcon="true" textField="MenuName" idField="MenuId" parentField="ParentId" resultAsTree="false"  
                    showCheckBox="true" checkRecursive="true" allowSelect="false" enableHotTrack="false">
                </ul>
            </div>
        </div>
    </div>
    </form>
    <script type="text/javascript">
        var _menu_right = "";
        var _urlParams = {};

        $(document).ready(function () {
            _urlParams = _UrlParams.convertKeyVal();
            if (_urlParams["type"] == "edit") {
                mini.get("UserName").disable();
                initData();
            }
        });

        function initData() {
            ygopAjaxClient.async("itm.sys.usermenu.getsingle", "post", { "umid": _urlParams["id"] }, function (e) {
                var result = mini.decode(e.data);
                var form = new mini.Form("#tb_userinfo");
                form.setData(result);
                if (result.MenuRights != null && result.MenuRights != "") {
                    _menu_right = result.MenuRights;
                    ygopAjaxClient.async("itm.sys.menu.getmenubyids", "post", { "mids": _menu_right }, function (e) {
                        mini.get("tree1").loadList(e.data, "id", "pid")
                    });
                }
            });
        }

        function onSelectMenu() {
            var tree = mini.get("tree2");
            _menu_right = tree.getValue(true);
            ygopAjaxClient.async("itm.sys.menu.getmenubyids", "post", { "mids": _menu_right }, function (e) {
                mini.get("tree1").loadList(e.data, "id", "pid")
                hideWindow();
            });
        }

        function openWin() {
            var win = mini.get("winTreeMenu");
            win.setTitle("选择页面权限");
            refreshNode()
            win.show();
        }

        function hideWindow() {
            var win = mini.get("winTreeMenu");
            win.hide();
        }

        function refreshNode() {
            var tree = mini.get("tree2");
            tree.setValue(0);
            var node = tree.getSelectedNode();
            if (node) {
                tree.loadNode(node);
            }
        }

        function saveData() {
            var form = new mini.Form("#tb_userinfo");
            form.validate();
            if (form.isValid() == false) return;
            var data = form.getData();
            data.MenuRights = _menu_right;
            data.IsAdmin = data.IsAdmin == "true" ? 1 : 0;
            var s = encodeURI(mini.encode(data));

            var method = "itm.sys.usermenu.add";
            if (_urlParams["type"] == "add") {
                method = "itm.sys.usermenu.add";
                if ($.trim(data.Password) == "") {
                    mini.alert("新增用户密码不能为空！");
                    return;
                }
            }
            else if (_urlParams["type"] == "edit")
                method = "itm.sys.usermenu.update";

            ygopAjaxClient.async(method, "post", { "s": s }, function (e) {
                if (e.RspCode == 1) {
                    mini.alert(e.RspMsg);
                    closePage();
                }
                else {
                    mini.alert(e.RspMsg);
                }
            });
        }

        function closePage() {
            _Popups.close();
            //parent.window.gridReload();
        }
    </script>
</body>
</html>
